#include "task_key.h"
#include "screen.h"
#include "key.h"
//#include "gpio.h"

TaskHandle_t keyHandler;
Sys_Sta sta;

void key_esc_silence(void)
{
	switch (sta.sc.layer)
	{
		case DEVICE_START_INIT:break;
		case DEVICE_START_SHOW_TIME:break;
		case DEVICE_START_DELAY_INFO:break;
		case DEVICE_START_LINE_INFO:break;
		case DEVICE_START_CHANNEL_INFO:break;
		case DEVICE_START_KEY_INFO:break;
		case DEVICE_PAGE_MAIN:
			{
				sta.silence = sta.silence == FALSE ? TRUE : FALSE;
			}break;
		case DEVICE_PAGE_MENU_MAIN:
			{
				sta.sc.layer = DEVICE_PAGE_MAIN;
			}break;
		case DEVICE_PAGE_MENU_PARAM_QUERY:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
			}break;
		case DEVICE_PAGE_MENU_PARAM_SET:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
			}break;
		case DEVICE_PAGE_MENU_DISABLE_CHANNEL:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
			}break;
		case DEVICE_PAGE_MENU_REMOTE_CALIBRATION:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
			}break;
		case DEVICE_PAGE_MENU_SYSTEM_EVENT:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
			}break;
		case DEVICE_PAGE_MENU_WARNING_EVENT:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
			}break;
		case DEVICE_PAGE_MENU_CHANNEL_INFO:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_QUERY;
			}break;
		case DEVICE_CHANNEL_INFO:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_CHANNEL_INFO;
			}break;
		case DEVICE_PAGE_MENU_LINE_INFO:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_QUERY;
			}break;
		case DEVICE_PAGE_SYSTEM_PARAM:
		{
			sta.sc.layer = DEVICE_PAGE_MENU_PARAM_QUERY;
		}break;
		case SYSTEM_PARAM_DELAY_TIME:
			{
				sta.sc.layer = DEVICE_PAGE_SYSTEM_PARAM;
			}break;
		case SYSTEM_PARAM_PATROL_SCREEN_CUTTING:
			{
				sta.sc.layer = DEVICE_PAGE_SYSTEM_PARAM;
			}break;
		case SYSTEM_PARAM_TIME_DATE:
			{
				sta.sc.layer = DEVICE_PAGE_SYSTEM_PARAM;
			}break;
		case SYSTEM_PARAM_COMPUTER_COMMUNICATION:
			{
				sta.sc.layer = DEVICE_PAGE_SYSTEM_PARAM;
			}break;
		case DEVICE_PAGE_STORE_STATUS:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_QUERY;
			}break;
		////////////////////////
		case SYSTEM_PARAM_SET_MENU_CHANNEL:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
			}break;
		case SYSTEM_PARAM_SET_MENU_LINE:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
			}break;
		case SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
			}break;
		case SYSTEM_PARAM_SET_MENU_CLEAR_EVENT:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
			}break;
		case SYSTEM_PARAM_SET_MENU_CHANGE_PASSWORD:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
			}break;
		case SYSTEM_PARAM_SET_MENU_DEBUG_SETTING:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
			}break;	
		case SYSTEM_PARAM_SET_MENU_CHANNEL_INFO:
			{
				sta.sc.layer = SYSTEM_PARAM_SET_MENU_CHANNEL;
			}break;	

		case SYSTEM_PARAM_SET_DELAY_TIME:
			{
				sta.sc.layer = SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM;
			}break;	
		case SYSTEM_PARAM_SET_PATROL_SCREEN_CUTTING:
			{
				sta.sc.layer = SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM;
			}break;	
		case SYSTEM_PARAM_SET_TIME_DATE:
			{
				sta.sc.layer = SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM;
			}break;	
		case SYSTEM_PARAM_SET_COMPUTER_COMMUNICATION:
			{
				sta.sc.layer = SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM;
			}break;	
		case DEVICE_PAGE_MENU_DISABLE_CHANNEL_INFO:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_DISABLE_CHANNEL;	
			}break;
		case DEVICE_PAGE_MENU_REMOTE_CALIBRATION_INFO:
			{
				sta.sc.layer = DEVICE_PAGE_MENU_REMOTE_CALIBRATION;	
			}break;
		case INPUT_SELECT:
		{
			if(get_input_select_ch() != 2)
			{
				set_input_select_ch(0);
			}else{
				sta.sc.layer = SYSTEM_PARAM_SET_MENU_CHANNEL_INFO;
			}
		}break;
		default:break;
	}
}

void key_up(void)
{
	switch (sta.sc.layer)
        {
			case DEVICE_START_INIT:break;
			case DEVICE_START_SHOW_TIME:break;
			case DEVICE_START_DELAY_INFO:break;
			case DEVICE_START_LINE_INFO:break;
			case DEVICE_START_CHANNEL_INFO:break;
			case DEVICE_START_KEY_INFO:break;
			case DEVICE_PAGE_MAIN:
				{
					if(sta.lock == FALSE)
					{
						main_ch_add();
					}
				}break;
			case DEVICE_PAGE_MENU_MAIN:
				{
					main_menu_ch_dec();
				}break;
			case DEVICE_PAGE_MENU_PARAM_QUERY:
				{
					param_query_menu_ch_dec();
				}break;
			case DEVICE_PAGE_MENU_PARAM_SET:
				{
					param_set_menu_ch_dec();
				}break;
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL:
				{
					disable_channel_menu_ch_dec();
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION:
				{
					remote_calibration_menu_ch_dec();
				}break;
			case DEVICE_PAGE_MENU_SYSTEM_EVENT:
				{
					menu_system_event_ch_dec();
				}
			case DEVICE_PAGE_MENU_WARNING_EVENT:
				{
					menu_warning_event_ch_dec();
				}break;
				
			case DEVICE_PAGE_MENU_CHANNEL_INFO:
				{
					menu_channel_info_ch_dec();
				}break;
				
			case DEVICE_CHANNEL_INFO:
				{
					if(sta.chnInfoType == CHN_INFO_TYPE_ONE)
					{
						sta.chnInfoType = CHN_INFO_TYPE_FOUR;
					}
					else if(sta.chnInfoType == CHN_INFO_TYPE_FOUR)
					{
						sta.chnInfoType = CHN_INFO_TYPE_THREE;
					}else if(sta.chnInfoType == CHN_INFO_TYPE_THREE)
					{
						sta.chnInfoType = CHN_INFO_TYPE_TWO;
					}else if(sta.chnInfoType == CHN_INFO_TYPE_TWO)
					{
						sta.chnInfoType = CHN_INFO_TYPE_ONE;
					}
				}break;
			case DEVICE_PAGE_SYSTEM_PARAM:
				{
					device_page_system_param_ch_dec();
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL:
				{
					system_param_set_menu_channel_ch_dec();
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL_INFO:
				{
					if(sta.sysParamSetInfoType == CHN_INFO_TYPE_ONE)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_FOUR;
					}
					else if(sta.sysParamSetInfoType == CHN_INFO_TYPE_FOUR)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_THREE;
					}else if(sta.sysParamSetInfoType == CHN_INFO_TYPE_THREE)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_TWO;
					}else if(sta.sysParamSetInfoType == CHN_INFO_TYPE_TWO)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_ONE;
					}
				}break;	
			case SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM:
				{
					system_param_set_menu_system_param_ch_dec();
				}break;
			case SYSTEM_PARAM_SET_MENU_DEBUG_SETTING:
				{
					system_param_set_menu_debug_setting_ch_dec();
				}break;
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL_INFO:
				{
					device_disable_channel_ch_dec();	
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION_INFO:
				{
					device_remote_calibration_ch_dec();	
				}break;
			case INPUT_SELECT:
				{
					switch(get_input_select_ch())
					{
						case 2:input_select_index_dec(3);break;
						case 4:py_select_index_dec(7);break;
						case 6:upper_select_index_dec(7);break;
						case 8:lower_select_index_dec(7);break;
						case 10:num_select_index_dec(5);break;
						case 12:symbol_select_index_dec(7);break;
						default:break;
					}
				}break;
		default:break;
        }
}

void key_menu_ok(void)
{
	switch (sta.sc.layer)
        {
			case DEVICE_START_INIT:break;
			case DEVICE_START_SHOW_TIME:break;
			case DEVICE_START_DELAY_INFO:break;
			case DEVICE_START_LINE_INFO:break;
			case DEVICE_START_CHANNEL_INFO:break;
			case DEVICE_START_KEY_INFO:break;
			case DEVICE_PAGE_MAIN:
				{
					sta.sc.layer = DEVICE_PAGE_MENU_MAIN;
				}break;
			case DEVICE_PAGE_MENU_MAIN:
				{
					switch(getMainMenuIndex())
					{
						case MENU_CH0:
							{
								sta.sc.layer = DEVICE_PAGE_MENU_PARAM_QUERY;
							}break;
						case MENU_CH1:
							{
								sta.sc.layer = DEVICE_PAGE_MENU_PARAM_SET;
							}break;
						case MENU_CH2:
							{
								sta.sc.layer = DEVICE_PAGE_MENU_DISABLE_CHANNEL;
							}break;
						case MENU_CH3:
							{
								sta.sc.layer = DEVICE_PAGE_MENU_REMOTE_CALIBRATION;
							}break;
						case MENU_CH4:
							{
								sta.sc.layer = DEVICE_PAGE_MENU_SYSTEM_EVENT;
							}break;
						case MENU_CH5:
							{
								sta.sc.layer = DEVICE_PAGE_MENU_WARNING_EVENT;
							}break;
						default:break;
					};
				}break;
			case DEVICE_PAGE_MENU_PARAM_QUERY:
				{
					switch(get_param_query_menu_Index())
					{
						case MENU_CH0:
							{	
								sta.sc.layer = DEVICE_PAGE_MENU_CHANNEL_INFO;
							}break;
						case MENU_CH1:
							{	
								sta.sc.layer = DEVICE_PAGE_MENU_LINE_INFO;
							}break;
						case MENU_CH2:
							{	
								sta.sc.layer = DEVICE_PAGE_SYSTEM_PARAM;
							}break;
						case MENU_CH3:
							{	
								sta.sc.layer = DEVICE_PAGE_STORE_STATUS;
							}break;
						default:break;
					}
				}break;
			case DEVICE_PAGE_MENU_PARAM_SET:
				{
					switch(get_param_set_menu_Index())
					{
						case MENU_CH0:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_MENU_CHANNEL;
							}break;
						case MENU_CH1:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_MENU_LINE;
							}break;
						case MENU_CH2:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM;
							}break;
						case MENU_CH3:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_MENU_CLEAR_EVENT;
							}break;
						case MENU_CH4:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_MENU_CHANGE_PASSWORD;
							}break;
						case MENU_CH5:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_MENU_DEBUG_SETTING;
							}break;
						default:break;
					}
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL:
				{
					sta.sc.layer = SYSTEM_PARAM_SET_MENU_CHANNEL_INFO;
				}break;
			case SYSTEM_PARAM_SET_MENU_LINE:
				{
				
				}break;	
			case SYSTEM_PARAM_SET_MENU_CLEAR_EVENT:
				{
				
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANGE_PASSWORD:
				{
				
				}break;
			case SYSTEM_PARAM_SET_MENU_DEBUG_SETTING:
				{
				
				}break;
			
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL:
				{
					sta.sc.layer = DEVICE_PAGE_MENU_DISABLE_CHANNEL_INFO;	
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION:
				{
					sta.sc.layer = DEVICE_PAGE_MENU_REMOTE_CALIBRATION_INFO;
				}break;
			case DEVICE_PAGE_MENU_SYSTEM_EVENT:break;
			case DEVICE_PAGE_MENU_WARNING_EVENT:break;
				
			case DEVICE_PAGE_MENU_CHANNEL_INFO:
				{
					sta.sc.layer = DEVICE_CHANNEL_INFO;	
				}break;
			case DEVICE_PAGE_SYSTEM_PARAM:
				{
					switch(get_device_page_system_param_Index())
					{
						case MENU_CH0:
							{	
								sta.sc.layer = SYSTEM_PARAM_DELAY_TIME;
							}break;
						case MENU_CH1:
							{	
								sta.sc.layer = SYSTEM_PARAM_PATROL_SCREEN_CUTTING;
							}break;
						case MENU_CH2:
							{	
								sta.sc.layer = SYSTEM_PARAM_TIME_DATE;
							}break;
						case MENU_CH3:
							{	
								sta.sc.layer = SYSTEM_PARAM_COMPUTER_COMMUNICATION;
							}break;
						default:break;
					}
				}break;
			case DEVICE_PAGE_STORE_STATUS:
				{
			
				}break;
			case SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM:
				{
					switch(get_system_param_set_menu_system_param_Index())
					{
						case MENU_CH0:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_DELAY_TIME;
							}break;
						case MENU_CH1:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_PATROL_SCREEN_CUTTING;
							}break;
						case MENU_CH2:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_TIME_DATE;
							}break;
						case MENU_CH3:
							{	
								sta.sc.layer = SYSTEM_PARAM_SET_COMPUTER_COMMUNICATION;
							}break;
						default:break;
					}
				}break;
				case SYSTEM_PARAM_SET_MENU_CHANNEL_INFO:
				{
					if(sta.sysParamSetInfoType == CHN_INFO_TYPE_ONE)
					{
						sta.sc.layer = INPUT_SELECT;
					}
				}break;
				case INPUT_SELECT:
				{

				}break;
				
			default:break;
        }
}

void key_left_switch(void)
{
	switch (sta.sc.layer)
        {
			case DEVICE_START_INIT:break;
			case DEVICE_START_SHOW_TIME:break;
			case DEVICE_START_DELAY_INFO:break;
			case DEVICE_START_LINE_INFO:break;
			case DEVICE_START_CHANNEL_INFO:break;
			case DEVICE_START_KEY_INFO:break;
			case DEVICE_PAGE_MAIN:
				{
					if(sta.mainType == MAIN_TYPE_ONE)
					{
						sta.mainType = MAIN_TYPE_TWO;
					}
					else if(sta.mainType == MAIN_TYPE_TWO)
					{
						sta.mainType = MAIN_TYPE_THREE;
					}else if(sta.mainType == MAIN_TYPE_THREE)
					{
						sta.mainType = MAIN_TYPE_ONE;
					}
					
					main_ch_clear();
					
					sta.lock = FALSE;
				}break;
			case DEVICE_PAGE_MENU_MAIN:
				{
					main_menu_ch_first();
				}break;
			case DEVICE_PAGE_MENU_PARAM_QUERY:
				{
					param_query_menu_ch_first();
				}break;
			case DEVICE_PAGE_MENU_PARAM_SET:
				{
					param_set_menu_ch_first();
				}break;
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL:
				{
					disable_channel_menu_ch_first();
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION:
				{
					remote_calibration_menu_ch_first();
				}break;
			case DEVICE_PAGE_MENU_SYSTEM_EVENT:
				{
					menu_system_event_ch_first();
				}break;
			case DEVICE_PAGE_MENU_WARNING_EVENT:
				{
					menu_warning_event_ch_first();
				}break;
			case DEVICE_CHANNEL_INFO:
				{
					sta.chnInfoType = CHN_INFO_TYPE_ONE;
				}break;
			case DEVICE_PAGE_SYSTEM_PARAM:
				{
					device_page_system_param_ch_first();
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL:
				{
					system_param_set_menu_channel_ch_first();
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL_INFO:
				{
					sta.sysParamSetInfoType = CHN_INFO_TYPE_ONE;
				}break;
			case SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM:
				{
					system_param_set_menu_system_param_ch_first();
				}break;
			case SYSTEM_PARAM_SET_MENU_DEBUG_SETTING:
				{
					system_param_set_menu_debug_setting_ch_first();
				}break;
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL_INFO:
				{
					device_disable_channel_ch_first();	
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION_INFO:
				{
					device_remote_calibration_ch_first();	
				}break;
			case INPUT_SELECT:
				{
					switch(get_input_select_ch())
					{
						case 2:input_select_index_dec(1);break;
						case 4:py_select_index_dec(1);break;
						case 6:upper_select_index_dec(1);break;
						case 8:lower_select_index_dec(1);break;
						case 10:num_select_index_dec(1);break;
						case 12:symbol_select_index_dec(1);break;
						default:break;
					}
				}break;
			default:break;
        }
}

void key_down(void)
{
	switch (sta.sc.layer)
        {
			case DEVICE_START_INIT:break;
			case DEVICE_START_SHOW_TIME:break;
			case DEVICE_START_DELAY_INFO:break;
			case DEVICE_START_LINE_INFO:break;
			case DEVICE_START_CHANNEL_INFO:break;
			case DEVICE_START_KEY_INFO:break;
			case DEVICE_PAGE_MAIN:
				{
					if(sta.lock == FALSE)
					{
						main_ch_dec();
					}
				}break;
			case DEVICE_PAGE_MENU_MAIN:
				{
					main_menu_ch_add();
				}break;
			case DEVICE_PAGE_MENU_PARAM_QUERY:
				{
					param_query_menu_ch_add();
				}break;
			case DEVICE_PAGE_MENU_PARAM_SET:
				{
					param_set_menu_ch_add();
				}break;
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL:
				{
					disable_channel_menu_ch_add();
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION:
				{
					remote_calibration_menu_ch_add();
				}break;
			case DEVICE_PAGE_MENU_SYSTEM_EVENT:
				{
					menu_system_event_ch_add();
				}break;
			case DEVICE_PAGE_MENU_WARNING_EVENT:
				{
					menu_warning_event_ch_add();
				}break;
			case DEVICE_PAGE_MENU_CHANNEL_INFO:
				{
					menu_channel_info_ch_add();
				}break;
				
			case DEVICE_CHANNEL_INFO:
			{
				if(sta.chnInfoType == CHN_INFO_TYPE_ONE)
				{
					sta.chnInfoType = CHN_INFO_TYPE_TWO;
				}
				else if(sta.chnInfoType == CHN_INFO_TYPE_TWO)
				{
					sta.chnInfoType = CHN_INFO_TYPE_THREE;
				}else if(sta.chnInfoType == CHN_INFO_TYPE_THREE)
				{
					sta.chnInfoType = CHN_INFO_TYPE_FOUR;
				}else if(sta.chnInfoType == CHN_INFO_TYPE_FOUR)
				{
					sta.chnInfoType = CHN_INFO_TYPE_ONE;
				}
			}break;		
			case DEVICE_PAGE_SYSTEM_PARAM:
				{
					device_page_system_param_ch_add();
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL:
				{
					system_param_set_menu_channel_ch_add();
				}break;
			case SYSTEM_PARAM_SET_MENU_CHANNEL_INFO:
				{
					if(sta.sysParamSetInfoType == CHN_INFO_TYPE_ONE)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_TWO;
					}
					else if(sta.sysParamSetInfoType == CHN_INFO_TYPE_TWO)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_THREE;
					}else if(sta.sysParamSetInfoType == CHN_INFO_TYPE_THREE)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_FOUR;
					}else if(sta.sysParamSetInfoType == CHN_INFO_TYPE_FOUR)
					{
						sta.sysParamSetInfoType = CHN_INFO_TYPE_ONE;
					}
				}break;	
			case SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM:
				{
					system_param_set_menu_system_param_ch_add();
				}break;
			case SYSTEM_PARAM_SET_MENU_DEBUG_SETTING:
				{
					system_param_set_menu_debug_setting_ch_add();
				}break;
			case DEVICE_PAGE_MENU_DISABLE_CHANNEL_INFO:
				{
					device_disable_channel_ch_add();	
				}break;
			case DEVICE_PAGE_MENU_REMOTE_CALIBRATION_INFO:
				{
					device_remote_calibration_ch_add();	
				}break;
			case INPUT_SELECT:
				{
					switch(get_input_select_ch())
					{
						case 2:input_select_index_add(3);break;
						case 4:py_select_index_add(7);break;
						case 6:upper_select_index_add(7);break;
						case 8:lower_select_index_add(7);break;
						case 10:num_select_index_add(5);break;
						case 12:symbol_select_index_add(7);break;
						default:break;
					}
				}break;
			default:break;
        }
}

void key_right_lock(void)
{
	switch (sta.sc.layer)
	{
		case DEVICE_START_INIT:break;
		case DEVICE_START_SHOW_TIME:break;
		case DEVICE_START_DELAY_INFO:break;
		case DEVICE_START_LINE_INFO:break;
		case DEVICE_START_CHANNEL_INFO:break;
		case DEVICE_START_KEY_INFO:break;
		case DEVICE_PAGE_MAIN:
			{
				sta.lock = sta.lock == FALSE ? TRUE : FALSE;
			}break;
		case DEVICE_PAGE_MENU_MAIN:
			{
				main_menu_ch_last();
			}break;
		case DEVICE_PAGE_MENU_PARAM_QUERY:
			{
				param_query_menu_ch_last();
			}break;
		case DEVICE_PAGE_MENU_PARAM_SET:
			{
				param_set_menu_ch_last();
			}break;
		case DEVICE_PAGE_MENU_DISABLE_CHANNEL:
			{
				disable_channel_menu_ch_last();
			}break;
		case DEVICE_PAGE_MENU_REMOTE_CALIBRATION:
			{
				remote_calibration_menu_ch_last();
			}break;
		case DEVICE_PAGE_MENU_SYSTEM_EVENT:
			{
				menu_system_event_ch_last();
			}break;
		case DEVICE_PAGE_MENU_WARNING_EVENT:
			{
				menu_warning_event_ch_last();
			}break;
		case DEVICE_CHANNEL_INFO:
			{
				sta.chnInfoType = CHN_INFO_TYPE_FOUR;
			}break;	
		case DEVICE_PAGE_SYSTEM_PARAM:
			{
				device_page_system_param_ch_last();
			}break;
		case SYSTEM_PARAM_SET_MENU_CHANNEL:
			{
				system_param_set_menu_channel_ch_last();
			}break;
		case SYSTEM_PARAM_SET_MENU_CHANNEL_INFO:
			{
				sta.sysParamSetInfoType = CHN_INFO_TYPE_FOUR;
			}break;
		case SYSTEM_PARAM_SET_MENU_SYSTEM_PARAM:
			{
				system_param_set_menu_system_param_ch_last();
			}break;
		case SYSTEM_PARAM_SET_MENU_DEBUG_SETTING:
			{
				system_param_set_menu_debug_setting_ch_last();
			}break;
		case DEVICE_PAGE_MENU_DISABLE_CHANNEL_INFO:
			{
				device_disable_channel_ch_last();	
			}break;
		case DEVICE_PAGE_MENU_REMOTE_CALIBRATION_INFO:
			{
				device_remote_calibration_ch_last();	
			}break;
		case INPUT_SELECT:
			{
				switch(get_input_select_ch())
				{
					case 2:input_select_index_add(1);break;
					case 4:py_select_index_add(1);break;
					case 6:upper_select_index_add(1);break;
					case 8:lower_select_index_add(1);break;
					case 10:num_select_index_add(1);break;
					case 12:symbol_select_index_add(1);break;
					default:break;
				}
			}break;
		default:break;
	}
}

void task_key(void *arg)
{
    while (1)
    {
		if (keys.key_flag == 0)
		{
			if(GPIO_ReadInputDataBit(ESC_SILENCE_PORT,ESC_SILENCE_PIN) == Bit_RESET)
			{
				TIM_Cmd(TIM2, ENABLE);
				keys.key_type = KEY_ESC_SILENCE;
			}
			
			if(GPIO_ReadInputDataBit(UP_PORT,UP_PIN) == Bit_RESET)
			{
				TIM_Cmd(TIM2, ENABLE);
				keys.key_type = KEY_UP;
			}
			
			if(GPIO_ReadInputDataBit(MENU_OK_PORT,MENU_OK_PIN) == Bit_RESET)
			{
				TIM_Cmd(TIM2, ENABLE);
				keys.key_type = KEY_MENU_OK;
			}
			
			if(GPIO_ReadInputDataBit(LEFT_SWITCH_PORT,LEFT_SWITCH_PIN) == Bit_RESET)
			{
				TIM_Cmd(TIM2, ENABLE);
				keys.key_type = KEY_LEFT_SWITCH;
			}
			
			if(GPIO_ReadInputDataBit(DOWN_PORT,DOWN_PIN) == Bit_RESET)
			{
				TIM_Cmd(TIM2, ENABLE);
				keys.key_type = KEY_DOWN;
			}
			
			if(GPIO_ReadInputDataBit(RIGHT_LOCK_PORT,RIGHT_LOCK_PIN) == Bit_RESET)
			{
				TIM_Cmd(TIM2, ENABLE);
				keys.key_type = KEY_RIGHT_LOCK;
			}
		}else{
			switch(keys.key_type)
			{
				case KEY_ESC_SILENCE:
				{
					key_esc_silence();
					
					keys.key_flag = 0;
				}break;
				case KEY_UP:
				{
					key_up();
					
					keys.key_flag = 0;
				}break;
				case KEY_MENU_OK:
				{
					key_menu_ok();
					
					if(sta.sc.layer != INPUT_SELECT)
					{
						keys.key_flag = 0;
					}
				}break;
				case KEY_LEFT_SWITCH:
				{
					key_left_switch();
					
					keys.key_flag = 0;
				}break;
				case KEY_DOWN:
				{
					key_down();
					
					keys.key_flag = 0;
				}break;
				case KEY_RIGHT_LOCK:
				{
					key_right_lock();
					
					keys.key_flag = 0;
				}break;
				default:{
					keys.key_flag = 0;
				}break;
			}	
		}
        vTaskDelay(100);
    }
}
